package com.panfeng.xcloud.boss.provider.assets.service.impl;

import com.alibaba.fastjson.JSON;
import com.panfeng.xcloud.boss.provider.assets.dao.mapper.WalletAssetsMapperExt;
import com.panfeng.xcloud.boss.provider.assets.dto.WalletAssetsExtendItemDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.request.QueryWalletAssetsPageReqDTO;
import com.panfeng.xcloud.boss.provider.assets.dto.response.QueryWalletAssetsPageRespDTO;
import com.panfeng.xcloud.boss.provider.assets.service.IWalletAssetsService;
import com.panfeng.xcloud.common.core.page.PageResponse;
import com.panfeng.xcloud.common.core.utils.ConvertUtils;
import com.panfeng.xcloud.dao.assets.entity.WalletAssets;
import com.panfeng.xcloud.dao.base.MapperSupport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class WalletAssetsServiceImpl extends MapperSupport<Integer, WalletAssets, WalletAssetsMapperExt> implements IWalletAssetsService {

    @Autowired
    WalletAssetsMapperExt walletAssetsMapperExt;

    /**
     * 查询相关资产
     * @param queryWalletAssetsPageReqDTO
     * @return
     */
    @Override
    public PageResponse<QueryWalletAssetsPageRespDTO> queryWalletAssets(QueryWalletAssetsPageReqDTO queryWalletAssetsPageReqDTO) {
        PageResponse<WalletAssetsExtendItemDTO> pageResponse = super.selectPage(queryWalletAssetsPageReqDTO, walletAssetsMapperExt::queryWalletAssetsExtPageCount, walletAssetsMapperExt::queryWalletAssetsExtPage);

        List<WalletAssetsExtendItemDTO> items = pageResponse.getItems();
        log.info(">>>> queryWalletAssets-items.list：{} <<<",(null != items ? JSON.toJSONString(items):""));
        List<QueryWalletAssetsPageRespDTO> queryWalletAssetsRespDTOS = ConvertUtils.convert(items, QueryWalletAssetsPageRespDTO.class);

        PageResponse<QueryWalletAssetsPageRespDTO> pageFinalResponse = new PageResponse();
        pageFinalResponse.setTotalCount(pageResponse.getTotalCount());
        pageFinalResponse.measureTotalPage(pageResponse.getTotalCount(),pageResponse.getPageSize());
        pageFinalResponse.setItems(queryWalletAssetsRespDTOS);
        pageFinalResponse.setPageNumber(pageResponse.getPageNumber());
        pageFinalResponse.setPageSize(pageResponse.getPageSize());

        return pageFinalResponse;
    }

}
